﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
namespace SecureCommander.Core.SecurityManager
{
    public class HashAlg
    {
        public string CreateSalt()
        {
            Random random = new Random();
            RNGCryptoServiceProvider rngcsp = new RNGCryptoServiceProvider();
            int SaltSize = random.Next(0, 20);
            byte[] ByteSalt = new byte[SaltSize];
            rngcsp.GetBytes(ByteSalt);
            //rngcsp.GetNonZeroBytes(ByteSalt);
            return Convert.ToBase64String(ByteSalt);
        }

        public string CreateHashFromPass_Salt(string passphrase, string salt)
        {
            //byte[] BytePass = ASCIIEncoding.ASCII.GetBytes(passphrase);
            byte[] ByteSalt = ASCIIEncoding.ASCII.GetBytes(salt);
            PasswordDeriveBytes password = new PasswordDeriveBytes(passphrase, ByteSalt);
            byte[] BytePassword = password.GetBytes(16);
            return Convert.ToBase64String(BytePassword);
        }
    }
}
